<?php
/**
 * Name: ClearCacheController.class.php
 * Description: 清理缓存
 * User: DIY
 * Date: 2016/9/8
 * Time: 17:19
 */

namespace Admin\Controller;


use Think\Controller;

class ClearCacheController extends Controller{

    public function index(){
        $this->delDir(RUNTIME_PATH);
        //删除文件缓存
        $this->success('清理缓存成功');

    }
    //递归删除文件
    private function delDir($dir){
        $dh = opendir($dir);
        while ($file = readdir($dh)) {
            if ($file != "." && $file != "..") {
                $fullpath = $dir . "/" . $file;
                if (!is_dir($fullpath)) {
                    unlink($fullpath);
                } else {
                    $this->delDir($fullpath);
                }
            }
        }
    }
}